﻿using Accouting804.Setting;
using System.Collections.ObjectModel;
using System.Linq;

namespace Accouting804.ViewModels.AccountViewModels
{
    /// <summary>
    /// 单个记录
    /// </summary>
    public class SingleAccoutViewModel : AccountsBaseViewModel
    {
        public AccountRecord Item { get; set; }
        public Category SelectedCategory
        {
            get => Categories.Where(category => category.Name == Item.Catagory).FirstOrDefault();
            set => Item.Catagory = value.Name;
        }

        public PaymentMethod SelectedPaymentMethod
        {
            get => PaymentMethods.Where(paymentmethod => paymentmethod.Name == Item.PaymentMethod).FirstOrDefault();
            set => Item.PaymentMethod = value.Name;
        }

        public Book SelectedBook
        {
            get => Books.Where(book => book.Name == Item.Book).FirstOrDefault();
            set => Item.Book = value.Name;
        }

        public SingleAccountViewModelType SingleAccountViewModelType { get; set; }

        public SingleAccoutViewModel()
        {

            
            Title = "单条记录";

            //CategoryDataStore.GetItemsAsync().ContinueWith((task) => Categories = new ObservableCollection<Category>(task.Result));

            //PaymentMethodDateStore.GetItemsAsync().ContinueWith((task) => PaymentMethods = new ObservableCollection<PaymentMethod>(task.Result));

            //BookDataStore.GetItemsAsync().ContinueWith(task => Books = new ObservableCollection<Book>(task.Result));

        }

    }
    public enum SingleAccountViewModelType
    {
        Insert, Edit, View
    }

}
